﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 DeliveryMethodManage
    /// </summary>
    public class DeliveryMethodManage : MarshalByRefObject
    {
        private static readonly DeliveryMethodDal Dal = new DeliveryMethodDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Logging]
        public Result Add(DeliveryMethod model)
        {
            Result res = new Result();
            if (model.MethodName.IsNullOrEmpty())
            {
                res.Errors = "“送货方式名称”不能为空！";
                return res;
            }


            if (model.Id == 0)
            {
                Dal.Add(model);
                res.LogMessage = "添加送货方式，" + model.MethodName;
            }
            else
            {
                Dal.Edit(model);

                res.LogMessage = "修改送货方式，" + model.MethodName;
            }

            return res;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public Result Delete(string IDs)
        {
            Result res = new Result();
            if (string.IsNullOrEmpty(IDs))
            {
                res.Errors = "至少选择一项。";
            }
            else
            {
                Dal.Delete(MyConvert.ConvertToArr(IDs));
            }
            return res;
        }

        #endregion

        /// <summary>
        /// 审核或者取消审核
        /// </summary>
        /// <param name="id"></param>
        [Logging("审核或者取消审核：{@p0}"), ExceptionCall]
        public void PassOrNo(int id)
        {
            Dal.PassOrNo(id);
        }

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DeliveryMethod GetInfo(int ID)
        {
            return Dal.GetInfo(ID);
        }

        #endregion

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="pp"></param>
        public IList<DeliveryMethod> BindList(PagingParam pp)
        {
            return Dal.BindList(pp);
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="rblDeliveryMethod"></param>
        public void BindList(RadioButtonList rblDeliveryMethod)
        {
            IList<DeliveryMethod> list = Dal.BindList();

            foreach (DeliveryMethod model in list)
            {
                ListItem item =
                    new ListItem(
                        model.MethodName + "（配送价格: <b>" + model.Charge.ToString("C") +
                        "</b>）<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + model.Intro, model.Id.ToString());
                if (model.IsDefault)
                {
                    item.Selected = true;
                }

                rblDeliveryMethod.Items.Add(item);
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <returns></returns>
        public IList<DeliveryMethod> GetList()
        {
            return Dal.BindList();
        }
    }
}